package com.ruoyi.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BaseDisease;
import com.ruoyi.base.service.IBaseDiseaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 病害操作Controller
 * 
 * @author ruoyi
 * @date 2024-01-06
 */
@RestController
@RequestMapping("/base/disease")
public class BaseDiseaseController extends BaseController
{
    @Autowired
    private IBaseDiseaseService baseDiseaseService;

    /**
     * 查询病害操作列表
     */
    @PreAuthorize("@ss.hasPermi('base:disease:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseDisease baseDisease)
    {
        startPage();
        List<BaseDisease> list = baseDiseaseService.selectBaseDiseaseList(baseDisease);
        return getDataTable(list);
    }

    /**
     * 导出病害操作列表
     */
    @PreAuthorize("@ss.hasPermi('base:disease:export')")
    @Log(title = "病害操作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseDisease baseDisease)
    {
        List<BaseDisease> list = baseDiseaseService.selectBaseDiseaseList(baseDisease);
        ExcelUtil<BaseDisease> util = new ExcelUtil<BaseDisease>(BaseDisease.class);
        util.exportExcel(response, list, "病害操作数据");
    }

    /**
     * 获取病害操作详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:disease:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseDiseaseService.selectBaseDiseaseById(id));
    }

    /**
     * 新增病害操作
     */
    @PreAuthorize("@ss.hasPermi('base:disease:add')")
    @Log(title = "病害操作", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseDisease baseDisease)
    {
        return toAjax(baseDiseaseService.insertBaseDisease(baseDisease));
    }

    /**
     * 修改病害操作
     */
    @PreAuthorize("@ss.hasPermi('base:disease:edit')")
    @Log(title = "病害操作", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseDisease baseDisease)
    {
        return toAjax(baseDiseaseService.updateBaseDisease(baseDisease));
    }

    /**
     * 删除病害操作
     */
    @PreAuthorize("@ss.hasPermi('base:disease:remove')")
    @Log(title = "病害操作", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseDiseaseService.deleteBaseDiseaseByIds(ids));
    }
}
